#region Imports
using System;
using System.Data;
using System.Data.SqlClient;

using BO = PHSRAG.Insight21.BusinessObjects;
using DataAccess = PHSRAG.Utility.DataAccess;
using ICachePolicy = PHSRAG.Insight21.Policy.ICachePolicy;
#endregion

namespace PHSRAG.Insight21.CDS
{
	/// <summary>
	/// Represents the set of certifications a user has
	/// </summary>
	public class Certifications : BO.BusinessObject
	{
		private const string CertificationsTableName = "Certifications";
		private const string CacheKey = "Certifications_B084814C-E130-4358-A477-FEED9B21A8A8";

		/// <summary>
		/// Initialitializes this instance with the specified cache policy
		/// </summary>
		/// <param name="cachePolicy">policy to use to cache this instance</param>
		public Certifications(ICachePolicy cachePolicy) : base(cachePolicy)
		{
		
		}

		/// <summary>
		/// Populates the dataContainer with all the certifications the user has
		/// </summary>
		/// <param name="connectionString">string containing information to connect to the database</param>
		/// <param name="args">arguments for the stored procedure</param>
		public override void Load(string connectionString, params object[] args)
		{
			try
			{
				if (args.Length != 1)
					throw new Exception("Certifications load requires an AdmPersonId");

				DataContainer = DataAccess.GetDataSet(
					connectionString,
					"GetPersonCertifications",
					DataAccess.BuildSqlParameterArray("@admPersonId", SqlDbType.Int, args[0]));

				DataContainer.Tables[0].TableName = CertificationsTableName;
			}

			catch(Exception e)
			{
				Utility.ExceptionReport.WriteToEventLog(
					"Certifications Load", e, true, Utility.ExceptionReport.ReportType.Error);
				throw new Exception("Load of Certifications failed", e);
			}
		}

		/// <summary>
		/// Puts this instance in the cache
		/// </summary>
		public override void Cache()
		{
			CachePolicy.Cache(CacheKey, this);
		}

		/// <summary>
		/// Removes this instance from the cache
		/// </summary>
		public override void UnCache()
		{
			CachePolicy.UnCache(CacheKey);
		}
	}
}
